<?php

use yii\helpers\Html;
use kartik\grid\GridView;
use common\models\business\BusinessSaleorder;

/* @var $this yii\web\View */
/* @var $searchModel backend\modules\business\models\BusinessSaleorderSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '订货单';
$this->params['breadcrumbs'][] = $this->title;
?>


<section class="wrapper site-min-height">
    <!-- page start-->
    <section class="panel">
        <header class="panel-heading">
              <?= Html::a('返回','javascript:history.back(-1)'); ?>  <?= Html::encode($this->title) ?>
        </header>
        <div class="panel-body">
            <div class="adv-table editable-table ">
 


<div class="business-saleorder-index">

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('添加订货单', ['create'], ['class' => 'btn btn-success']) ?>
    </p>


    <?php
    echo GridView::widget([
        'dataProvider'=>$dataProvider,
        'filterModel'=>$searchModel,
        'showPageSummary'=>true,
        'pjax'=>false,
        'striped'=>true,
        'hover'=>true,
        'panel'=>['type'=>'primary', 'heading'=>'订货单管理'],
        'containerOptions'=>['style'=>'overflow: auto'], // only set when $responsive = false
        'headerRowOptions'=>['class'=>'kartik-sheet-style'],
        'filterRowOptions'=>['class'=>'kartik-sheet-style'],
        'columns'=>[
            [
                'attribute'=>'ordersn',
                'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                'width'=>'100px',
            ],
            [
                'label' => '客户',
                'attribute'=>'customername',
                'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                'width'=>'100px',
            ],
            [
                'attribute'=>'price',
                'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                'width'=>'100px',
            ],
            [
                'attribute'=>'createtime',
                'value' => function($model){
                    return date('Y-m-d H:i:s',$model->createtime);
                },
                'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                'width'=>'100px',
            ],
            [
                'attribute'=>'paytime',
                'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                'width'=>'100px',
                'value' => function($model){
                    if($model->paytime == 0){
                        return '未付款';
                    }
                    return date('Y-m-d H:i:s',$model->paytime);
                },
            ],
            [
                'attribute'=>'senddate',
                'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                'width'=>'100px',
                'value' => function($model){
                    if($model->paytime == 0){
                        return '未发货';
                    }
                    return date('Y-m-d H:i:s',$model->senddate);
                },
            ],
            [
                'attribute'=>'status',
                'width'=>'100px',
                'format' => 'raw',
                'value'=>function ($model, $key, $index, $widget) {
                    return BusinessSaleorder::$statues[$model->status];
                },
                'filterType'=>GridView::FILTER_SELECT2,
                'filter'=> BusinessSaleorder::$statues,
                'filterWidgetOptions'=>[
                    'pluginOptions'=>['allowClear'=>true],
                ],
                'filterInputOptions'=>['placeholder'=>'选择状态']
            ],
            [
                'attribute'=>'isagree',
                'width'=>'100px',
                'format' => 'raw',
                'value'=>function ($model, $key, $index, $widget) {
                    return BusinessSaleorder::$agree[$model->isagree];
                },
                'filterType'=>GridView::FILTER_SELECT2,
                'filter'=> BusinessSaleorder::$agree,
                'filterWidgetOptions'=>[
                    'pluginOptions'=>['allowClear'=>true],
                ],
                'filterInputOptions'=>['placeholder'=>'选择状态']
            ],
            [
                'class' => '\kartik\grid\ActionColumn',
                'template' => '{view} {update} {delete} {agree}',
                'buttons' => [
                    'agree' => function ($url, $model) {
                        return Html::a('审核通过','/business/saleorder/agree?id='.$model->id,[
                            'title' => '审核通过','class'=>'agree','data-id'=>$model->id,
                        ]);
                    }
                ],
            ],

            [
                'class' => '\kartik\grid\CheckboxColumn'
            ]
        ],
        'toolbar'=> [
            '{export}',
            '{toggleData}',
        ],
        'bordered'=>true,
        'condensed'=>true,
    ]);
    ?>

</div>
</div>
</div>
</section>
</section>





